github.com/waldiirawan/apm-agent-go/v2@v2.2.2/stacktrace/library.go (about)

     1  // Licensed to Elasticsearch B.V. under one or more contributor
     2  // license agreements. See the NOTICE file distributed with
     3  // this work for additional information regarding copyright
     4  // ownership. Elasticsearch B.V. licenses this file to you under
     5  // the Apache License, Version 2.0 (the "License"); you may
     6  // not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing,
    12  // software distributed under the License is distributed on an
    13  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14  // KIND, either express or implied.  See the License for the
    15  // specific language governing permissions and limitations
    16  // under the License.
    17  
    18  // Code generated by "go generate". DO NOT EDIT.
    19  
    20  package stacktrace // import "github.com/waldiirawan/apm-agent-go/v2/stacktrace"
    21  
    22  import (
    23  	"strings"
    24  
    25  	radix "github.com/armon/go-radix"
    26  )
    27  
    28  var libraryPackages = newLibraryPackagesRadixTree(
    29  	"vendor/golang_org",
    30  	"archive/tar",
    31  	"archive/zip",
    32  	"bufio",
    33  	"bytes",
    34  	"compress/bzip2",
    35  	"compress/flate",
    36  	"compress/gzip",
    37  	"compress/lzw",
    38  	"compress/zlib",
    39  	"container/heap",
    40  	"container/list",
    41  	"container/ring",
    42  	"context",
    43  	"crypto",
    44  	"crypto/aes",
    45  	"crypto/cipher",
    46  	"crypto/des",
    47  	"crypto/dsa",
    48  	"crypto/ecdsa",
    49  	"crypto/elliptic",
    50  	"crypto/hmac",
    51  	"crypto/internal/randutil",
    52  	"crypto/internal/subtle",
    53  	"crypto/md5",
    54  	"crypto/rand",
    55  	"crypto/rc4",
    56  	"crypto/rsa",
    57  	"crypto/sha1",
    58  	"crypto/sha256",
    59  	"crypto/sha512",
    60  	"crypto/subtle",
    61  	"crypto/tls",
    62  	"crypto/x509",
    63  	"crypto/x509/pkix",
    64  	"database/sql",
    65  	"database/sql/driver",
    66  	"debug/dwarf",
    67  	"debug/elf",
    68  	"debug/gosym",
    69  	"debug/macho",
    70  	"debug/pe",
    71  	"debug/plan9obj",
    72  	"encoding",
    73  	"encoding/ascii85",
    74  	"encoding/asn1",
    75  	"encoding/base32",
    76  	"encoding/base64",
    77  	"encoding/binary",
    78  	"encoding/csv",
    79  	"encoding/gob",
    80  	"encoding/hex",
    81  	"encoding/json",
    82  	"encoding/pem",
    83  	"encoding/xml",
    84  	"errors",
    85  	"expvar",
    86  	"flag",
    87  	"fmt",
    88  	"go/ast",
    89  	"go/build",
    90  	"go/constant",
    91  	"go/doc",
    92  	"go/format",
    93  	"go/importer",
    94  	"go/internal/gccgoimporter",
    95  	"go/internal/gcimporter",
    96  	"go/internal/srcimporter",
    97  	"go/parser",
    98  	"go/printer",
    99  	"go/scanner",
   100  	"go/token",
   101  	"go/types",
   102  	"hash",
   103  	"hash/adler32",
   104  	"hash/crc32",
   105  	"hash/crc64",
   106  	"hash/fnv",
   107  	"html",
   108  	"html/template",
   109  	"image",
   110  	"image/color",
   111  	"image/color/palette",
   112  	"image/draw",
   113  	"image/gif",
   114  	"image/internal/imageutil",
   115  	"image/jpeg",
   116  	"image/png",
   117  	"index/suffixarray",
   118  	"internal/bytealg",
   119  	"internal/cpu",
   120  	"internal/nettrace",
   121  	"internal/poll",
   122  	"internal/race",
   123  	"internal/singleflight",
   124  	"internal/syscall/unix",
   125  	"internal/syscall/windows",
   126  	"internal/syscall/windows/registry",
   127  	"internal/syscall/windows/sysdll",
   128  	"internal/testenv",
   129  	"internal/testlog",
   130  	"internal/trace",
   131  	"io",
   132  	"io/ioutil",
   133  	"log",
   134  	"log/syslog",
   135  	"math",
   136  	"math/big",
   137  	"math/bits",
   138  	"math/cmplx",
   139  	"math/rand",
   140  	"mime",
   141  	"mime/multipart",
   142  	"mime/quotedprintable",
   143  	"net",
   144  	"net/http",
   145  	"net/http/cgi",
   146  	"net/http/cookiejar",
   147  	"net/http/fcgi",
   148  	"net/http/httptest",
   149  	"net/http/httptrace",
   150  	"net/http/httputil",
   151  	"net/http/internal",
   152  	"net/http/pprof",
   153  	"net/internal/socktest",
   154  	"net/mail",
   155  	"net/rpc",
   156  	"net/rpc/jsonrpc",
   157  	"net/smtp",
   158  	"net/textproto",
   159  	"net/url",
   160  	"os",
   161  	"os/exec",
   162  	"os/signal",
   163  	"os/signal/internal/pty",
   164  	"os/user",
   165  	"path",
   166  	"path/filepath",
   167  	"plugin",
   168  	"reflect",
   169  	"regexp",
   170  	"regexp/syntax",
   171  	"runtime",
   172  	"runtime/cgo",
   173  	"runtime/debug",
   174  	"runtime/internal/atomic",
   175  	"runtime/internal/sys",
   176  	"runtime/pprof",
   177  	"runtime/pprof/internal/profile",
   178  	"runtime/race",
   179  	"runtime/trace",
   180  	"sort",
   181  	"strconv",
   182  	"strings",
   183  	"sync",
   184  	"sync/atomic",
   185  	"syscall",
   186  	"testing",
   187  	"testing/internal/testdeps",
   188  	"testing/iotest",
   189  	"testing/quick",
   190  	"text/scanner",
   191  	"text/tabwriter",
   192  	"text/template",
   193  	"text/template/parse",
   194  	"time",
   195  	"unicode",
   196  	"unicode/utf16",
   197  	"unicode/utf8",
   198  	"unsafe",
   199  	"github.com/waldiirawan/apm-agent-go",
   200  )
   201  
   202  func newLibraryPackagesRadixTree(k ...string) *radix.Tree {
   203  	tree := radix.New()
   204  	for _, k := range k {
   205  		tree.Insert(k, true)
   206  	}
   207  	return tree
   208  }
   209  
   210  // RegisterLibraryPackage registers the given packages as being
   211  // well-known library path prefixes. This must not be called
   212  // concurrently with any other functions or methods in this
   213  // package; it is expected to be used by init functions.
   214  func RegisterLibraryPackage(pkg ...string) {
   215  	for _, pkg := range pkg {
   216  		libraryPackages.Insert(pkg, true)
   217  	}
   218  }
   219  
   220  // RegisterApplicationPackage registers the given packages as being
   221  // an application path. This must not be called concurrently with
   222  // any other functions or methods in this package; it is expected
   223  // to be used by init functions.
   224  //
   225  // It is not typically necessary to register application paths. If
   226  // a package does not match a registered *library* package path
   227  // prefix, then the path is considered an application path. This
   228  // function exists for the unusual case that an application exists
   229  // within a library (e.g. an example program).
   230  func RegisterApplicationPackage(pkg ...string) {
   231  	for _, pkg := range pkg {
   232  		libraryPackages.Insert(pkg, false)
   233  	}
   234  }
   235  
   236  // IsLibraryPackage reports whether or not the given package path is
   237  // a library package. This includes known library packages
   238  // (e.g. stdlib or apm-agent-go), vendored packages, and any packages
   239  // with a prefix registered with RegisterLibraryPackage but not
   240  // RegisterApplicationPackage.
   241  func IsLibraryPackage(pkg string) bool {
   242  	if strings.HasSuffix(pkg, "_test") {
   243  		return false
   244  	}
   245  	if strings.Contains(pkg, "/vendor/") {
   246  		return true
   247  	}
   248  	prefix, v, ok := libraryPackages.LongestPrefix(pkg)
   249  	if !ok || v == false {
   250  		return false
   251  	}
   252  	return prefix == pkg || pkg[len(prefix)] == '/'
   253  }